package com.example.Service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.Service.UserService;
import com.example.dao.UserMapper;
import com.example.pojo.User;
import com.example.util.MD5;
import com.example.util.PasswordUtils;
import com.example.util.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Autowired
    private UserMapper userMapper;

    //wjc
    public PageInfo<User> selecAllProduct(User user, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> list = userMapper.selecAllProduct(user);
        return new PageInfo<>(list);
    }

    public void updateProduct(User user) {
        userMapper.updateProduct(user);
    }

    public void addProduct(User user) {
        userMapper.addProduct(user);
    }

    public PageInfo<User> selectAllItPage(User user, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list = userMapper.selectItPage(user);
        return new PageInfo<>(list);
    }

    //所有It部门的信息
    public List<User> selectAllItInfo() {
        return userMapper.selectAllItInfo();
    }

    //dsf
    //分页查询
    public PageInfo<User> selectAll(String name, Integer id, Integer departmentId, Integer positionId, Integer PageNum, Integer PageSize){
        PageHelper.startPage(PageNum,PageSize);
        List<User> users = userMapper.selectAll(name, id, departmentId, positionId);
        return new PageInfo<>(users);
    }

    //查询id
    public User selectOne(Integer id){
        User user = userMapper.selectOne(id);
        return user;
    }

    //查询姓名
    public User selectJump(String name){
        User user = userMapper.selectJump(name);
        return user;
    }

    public User realNameAuthentication(String id) {
        User user = userMapper.realNameAuthentication(id);
        return user;
    }


    public void updatePassword(Integer id) {
        String password = PasswordUtils.encrypt(MD5.encrypt("123456"));
        userMapper.updatePassword(id,password);
    }

    public void updateUserPassword(User user) {
        String password = PasswordUtils.encrypt(MD5.encrypt(user.getPassword()));
        userMapper.updateUserPassword(user.getId(),password);
    }

    public User selectPassword(Integer id) {
        return userMapper.selectOne(id);
    }

    public int checkPassword(Integer id, String password) {
        return userMapper.checkPassword(id, password);
    }


//    public Result selectPassword(Integer id) {
//        User user = userMapper.selectOne(id);
//        if (user == null){
//            return  new Result("500","用户不存在",null);
//        }
//        return new Result("200","查询成功",user);
//    }
}
